<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
</head>
<body>
    <input type="text" id="txt1">
    <input type="button" value="校验" id="btn1">

    <script>
        window.onload = function() {
            let oTxt = document.getElementById('txt1');
            let oBtn = document.getElementById('btn1');

            oBtn.onclick = function() {
                // ^表示开始 $表示结束 若不限定开始和结束会有问题
                let re = /^[1-9]\d{4,11}$/;
                if(re.test(oTxt.value)){
                    alert('通过');
                } else {
                    alert('不对');
                }
            };
            
        };
    </script>
</body>
</html>